﻿using System;
using System.Collections.Generic;

using System.Text;

namespace GGSharp.Structures
{
    public class NotifyStruct : StuctureBase
    {
        protected const int USER_BUDDY_MASK = 0x01;
        protected const int USER_FRIEND_MASK = 0x02;
        protected const int USER_BLOCKED_MASK = 0x04;

        private int _uin = 0;

        private bool _blocked = false;
        private bool _buddy = true;
        private bool _friend = true;

        public NotifyStruct()
        {
            this.Length = 5;
        }

        public NotifyStruct(int uin)
            : this()
        {
            _uin = uin;
        }

        public bool IsBlocked
        {
            get { return _blocked; }
            set { _blocked = value; }
        }

        public bool IsBuddy
        {
            get { return _buddy; }
            set { _buddy = value; }
        }

        public bool IsFriend
        {
            get { return _friend; }
            set { _friend = value; }
        }

        public int Number
        {
            get { return _uin; }
            set { _uin = value; }
        }

        public override void Read(System.IO.BinaryReader reader)
        {
            _uin = reader.ReadInt32();
            byte type = reader.ReadByte();
            _blocked = (type & USER_BLOCKED_MASK) == USER_BLOCKED_MASK ? true : false;
            _buddy = (type & USER_BUDDY_MASK) == USER_BUDDY_MASK ? true : false;
            _friend = (type & USER_FRIEND_MASK) == USER_FRIEND_MASK ? true : false;

            ReadedLength = 5;
        }

        public override void Write(System.IO.BinaryWriter writer)
        {
            writer.Write(_uin);

            byte type = 0;
            type = (byte)(_blocked ? type | USER_BLOCKED_MASK : type);
            type = (byte)(_buddy ? type | USER_BUDDY_MASK : type);
            type = (byte)(_friend ? type | USER_FRIEND_MASK : type);
            writer.Write(type);
        }
    }
}
